$(function () {
    $("#page").load("/html/page.html");
    selectGroup();
});

function selectGroup() {
    let result = myAjax('/group/selectAll', 'post', {});
    let html = " <option value='0'>全部</option>";
    for (let i = 0; i < result.list.length; i++) {
        html += ' <option value="' + result.list[i].id + '">' + result.list[i].name + '</option>';
    }
    $("#team").html(html);
}

function searchAll() {
    let data = {};
    data.userName = $("#userName").val();
    data.team = $("#team").find("option:selected").text();
    data.signDate = $("#signDate").val();
    data.pageNum = $.trim($("#pageNum").val());
    data.pageSize = $.trim($("#pageSize").val());
    let result = myAjax('/sign/findAll', 'post', data);
    showData(result.list);
    $("#pageCount").html(result.number);
}

function showData(data) {
    let html = "";
    let attendance;
    for (let i = 0; i < data.length; i++) {
        if (data[i].state==="正常"&&data[i].outState==="正常"){
            attendance = "正常";
        }else if (data[i].state ==="迟到"&&data[i].outState==="正常"){
            attendance = "迟到";
        }else if (data[i].state ==="正常"&&data[i].outState==="早退"){
            attendance="早退";
        }else if (data[i].state ==="请假"||data[i].outState==="请假"){
            attendance="请假";
        }else if (data[i].state ==="迟到"&&data[i].outState==="早退"){
            attendance="缺勤"
        }
        html += '   <tr> ' +
            '  <td><input type="checkbox" name="isCheck" value="' + data[i].id + '">' + data[i].id + '</td>\n' +
            '        <td>' + data[i].signDate + '</td>\n' +
            '        <td>' + data[i].userName + '</td>\n' +
            '        <td>' + data[i].team + '</td>\n' +
            '        <td>' + attendance + '</td>\n' +
            '        <td>' + data[i].signTime + '</td>\n' +
            '        <td>' + data[i].outTime + '</td>\n' +
            '        <td><input type="button" style="width: 60px;border-radius: 5px;' +
            'background-color: red" value="删除" onclick="del(`' + data[i].signDate + '`,`'+data[i].userName+'`)"></td>' +
            '    </tr>';
    }
    $("#findAll").html(html);
}

function del(data,name) {
    console.log(data,name);
    layer.confirm("确定删除吗？","",function () {
        let result = myAjax("/sign/signDelete", "post", {signDate: data,userName:name})
        if (result === 1) {
            layer.msg("删除成功");
            searchAll();
        }
    });
}
layui.use('layer');
